package com.whitedust.top40;

import com.whitedust.structure.ListNode;

import java.util.List;

/**
 * @author A
 * @since 2025/11/5 10:36
 */

public class Top35 {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) return null;
        ListNode dummy = new ListNode(head.val - 1, head);
        ListNode pre = dummy;
        ListNode cur = head;
        ListNode next = cur.next;
        while (cur != null && next != null) {
            if (cur.val == next.val) {
                while (next != null && cur.val == next.val) {
                    cur = next;
                    next = next.next;
                }
                pre.next = next;
                cur = next;
                next = next == null ? null : next.next;
                continue;
            }
            pre = cur;
            cur = next;
            next = next.next;
        }
        return dummy.next;
    }
}
